#!/bin/bash
SCRIPT_BASE_DIR=$( dirname "${BASH_SOURCE[0]}" )
source "${SCRIPT_BASE_DIR}/common/fs_utils.sh"
source "${SCRIPT_BASE_DIR}/common/cs_utils.sh"

function usage () {
	echo "Usage: $( basename "$0" ) [-t] [<root_dir>]"
    echo "     对<root_dir>内指定文件建立cscope数据库"
    echo "     -t: 包含test目录,缺省不包含"
    echo "     root_dir: 源代码根目录,缺省为当前目录"
	exit 1
}

# 要排除的文件目录全名
excludeNames=(build test)
while getopts ":t" arg
do
    case ${arg} in
        t)
            # 从excludeNames里删除test
            unset excludeNames[1]
            shift
            ;;
        ?)
            echo "Error: unknown args: ${OPTARG}"
            usage
            ;;
    esac
done

root=.
# 其余的参数
if [ $# -gt 0 ]
then
    root="$1"
fi

# 要搜索的文件扩展名
exts=(cpp cc c hpp h arxml json cmake cmake.in py sh)
# 要搜索的文件全名
fnames=(CMakeLists.txt CMakeLists_pre.txt CMakeLists_post.txt)

# 传递数组变量名字
build_cs_file_list "${root}" exts fnames excludeNames

{
    echo "Build cscope DB in ${root} ..."
    cd ${root}
    cscope -Rbqk
}

echo "Done."

